package com.example.opengldemo;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.opengl.GLES20;
import android.opengl.GLUtils;
import android.util.Log;

public class TextureHelper {

    public static int loadTexture(Context context,int resourceId){

        int textureObjectIds[] = new int[1];

        GLES20.glGenTextures(1,textureObjectIds,0);

        if(textureObjectIds[0]==0){
            Log.e("androidLog","Could not generate a new OpenGL texture object.");
            return 0;
        }

        Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(),resourceId);
        if(bitmap==null){
            Log.e("androidLog","Resource Id "+resourceId+" could not be decoded.");
            GLES20.glDeleteTextures(1,textureObjectIds,0);
            return 0;
        }

        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D,textureObjectIds[0]);

        GLUtils.texImage2D(GLES20.GL_TEXTURE_2D,0,bitmap,0);

        bitmap.recycle();

        GLES20.glGenerateMipmap(GLES20.GL_TEXTURE_2D);

        return textureObjectIds[0];

    }

























































}
